<?php

class Utility
{

    public static function getActivationKey( $seed )
    {
        return md5( uniqid( $seed ) );
    }



    public static function hashedPassword( $salt, $password )
    {
        return sha1( $salt . sha1( $password ) );
    }



    public static function generatePassword( $length = 8 )
    {
        $chars = '!#%+23456789:=?@ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
        $count = mb_strlen( $chars );

        for ( $i = 0, $result = ''; $i < $length; $i++ )
        {
            $index = mt_rand( 0, $count - 1 );
            $result .= mb_substr( $chars, $index, 1 );
        }
        return $result;
    }



    public static function getHash( $string )
    {
        preg_match_all( '~(?!\b)(#\w+)(?=\s|$)~', $string, $matches );

        if ( count( $matches[ 1 ] ) > 0 )
        {
            return array_unique( array_map( 'strtolower', $matches[ 1 ] ), SORT_STRING );
        }

        return false;
    }



    public static function createThumb( $source, $destination, $attr = null )
    {
        $targ_width = $targ_height = 150;
        $quality = 90;
        $source_img = $source;
        $img_r = imagecreatefromjpeg( $source_img );
        $dst_r = ImageCreateTrueColor( $targ_width, $targ_height );
        imagecopyresampled( $dst_r, $img_r, 0, 0, $attr[ 'x' ], $attr[ 'y' ], $targ_width, $targ_height, $attr[ 'w' ], $attr[ 'h' ] );
        imagejpeg( $dst_r, $destination, $quality );
    }



}
?>


